#!/bin/bash
rm -rf skdk.sh
clear
    echo "- - - -- - - - - - - -- - - - - -- - - - - -- - - - - -- - - - - -- "
echo "     欢迎使用SSR/SS开端口脚本"
    echo "- - - -- - - - - - - -- - - - - -- - - - - -- - - - - -- - - - - -- "
echo "     说明: 执行后可以添加端口，添加端口不会删除原来的端口"
    echo "- - - -- - - - - - - -- - - - - -- - - - - -- - - - - -- - - - - -- "
echo 
cd /root
myip=`wget http://ipecho.net/plain -O - -q ; echo`
echo -e "\e[1;37m请输入一个需要添加的端口[本机IP是:$myip]\e[0m"
read -p "(回车将默认添加端口:8081):" PORT
[ -z "$PORT" ] && PORT="8081"
        echo
        echo -e "---------------------------"
        echo -e "将要添加的端口是 = $PORT"
        echo -e "---------------------------"
        echo
echo -e "请设置$PORT端口的密码"
read -p "(回车将设置默认密码:shangsu):" mi
[ -z "$mi" ] && mi="shangsu"
        echo 
        echo -e "---------------------------"
        echo -e "您设置$PORT端口的密码为 = $mi"
        echo -e "---------------------------"
        echo 
sleep 3
echo -e "\e[1;31m正在配置防火墙...\e[0m"
iptables -A OUTPUT -p tcp --dport $PORT -j ACCEPT >/dev/null 2>&1
iptables -A INPUT -p tcp --sport $PORT -j ACCEPT >/dev/null 2>&1
iptables -A INPUT -p tcp --dport $PORT -j ACCEPT >/dev/null 2>&1
iptables -A OUTPUT -p tcp --sport $PORT -j ACCEPT >/dev/null 2>&1
echo -e "\e[1;31m正在重启防火墙...\e[0m"
service iptables save
service iptables restart
sleep 5
cd /etc
sed -i "7a\"$PORT\":\"$MM\"," shadowsocks.json >/dev/null 2>&1
cd /root
echo -e "\e[1;31m正在重启SSR/SS服务...\e[0m"
service shadowsocks restart
rm -rf skdk.sh
clear
echo "- - - -- - - - - - - -- - - - - -- - - - - -- - - - - -- - - - - -- "
echo "     欢迎使用SSR/SS开端口脚本"
echo "     $PORT端口已添加成功"
echo "     连接密码为$mi"
echo "     添加更多端口重新执行本脚本即可添加"
echo "- - - -- - - - - - - -- - - - - -- - - - - -- - - - - -- - - - - -- "
